<?php
namespace Common\Controller;
use Think\Controller;

class BaseController extends Controller {

    static  $action         =       0;
    static  $token          = '';//md5('1234')
    static  $home_page      = '';
    
    public  $userid         = 0;
    public  $role           = 0;
    public  $company_r_id   = 0;

    public function _initialize(){
        
        self::$token = C('token');
        self::$home_page = U('Home/Index/index');

        $this->assign('action',self::$action);
        // $this->assign('menus',C('menus'));
        $this->assign('token',self::$token);

        if(empty($_SESSION['USER'])){
            $this->_checkLogin();
        }
       $this->userid = $_SESSION['USER']['INFO']['user_id'];
       $this->role   = $_SESSION['USER']['INFO']['role_id'];

       if(!empty($_SESSION['USER']['COMPANY'])){
            $this->company_r_id =  $_SESSION['USER']['COMPANY']['company_id'];
       }
       
       $this->assign('session',$_SESSION);
    }
    public function index(){
        echo "BaseController";
    }
    protected function _checkLogin(){
        $redirect_url = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
        $url = strtolower($redirect_url);
        if(!in_array($url,C('nologin_page'))){
            $redirect_url = U($redirect_url);
            redirect(U('Home/User/Login',array('url'=>base64_encode($redirect_url))));
        }
    }
}